<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var str = "http://www.zhufengpeixun.cn?name=lili&age=18#123"
    /* 
     search: "?name=lili&age=18"
     hash: "#123"
    */

    function queryParams(str) {
      var a = document.createElement("a");
      a.href = str;
      var obj = {};
      console.log(a.search); //?name=lili&age=18
      console.log(a.hash); //#123
      //[name=lili,age=18]
      var search = a.search.substr(1);
      console.log(search);//name=lili&age=18
      obj.hash = a.hash ? a.hash : null;
      if (search) {
        var searchAry = search.split("&");
        console.log(searchAry)// ['name=lili', 'age=18']
        for (var i = 0; i < searchAry.length; i++) {
          var itemAry = searchAry[i];//name=lili  age=18
          var item = itemAry.split("=");
          console.log(item)//['name', 'lili']['age', '18']
          var key = item[0];
          var value = item[1];
          obj[key] = value;
        }
      }
      return obj;
    }
    var dd = queryParams(str);
    console.log(dd)
  </script>
</body>

</html>